/*
 	圆桌添加
 * 
 * */



//创建div酒席
function Adddata(xishu){
	var div = document.createElement("div");	
	var str = 
	'<div class="bigtable">第'+xishu+'席</div>'+
	'<div class="zhuowei a1"><i class="iconfont icon-lianxiren"></i></div>'+
	'<div class="zhuowei a2"><i class="iconfont icon-lianxiren"></i></div>'+
	'<div class="zhuowei a3"><i class="iconfont icon-lianxiren"></i></div>'+
	'<div class="zhuowei a4"><i class="iconfont icon-lianxiren"></i></div>'+
	'<div class="zhuowei a5"><i class="iconfont icon-lianxiren"></i></div>'+
	'<div class="zhuowei a6"><i class="iconfont icon-lianxiren"></i></div>';	
	div.innerHTML = str;
	div.setAttribute('class','jiuxishu');
	return div;
}

var addBtn = document.getElementById('addBtn');
var contentmsg = document.getElementById('content');
var jiuxinum  = contentmsg.getElementsByClassName('jiuxishu');
var createBtn = document.getElementById('createBtn');
var tc = document.querySelector('.pop-up-windows');
var index = 0;
var maxtc = document.querySelector('.pop-up-windows2');
var closeBtn2 = document.querySelector('.closeBtn2');
var mintc = document.querySelector('.pop-up-windows3');
var closeBtn3 = document.querySelector('.closeBtn3');

//添加按钮绑定事件
addBtn.addEventListener('click',function(){
	var arr= [];
	for(var i=0;i<jiuxinum.length;i++){
		arr.push(i);
	}
	index = Math.max(...arr);//拿到当前最大的酒席数
	var div = Adddata(index+1);
	if(index<10){  //只能定制十围
		//在倒数第一个之前添加
		contentmsg.insertBefore(div,jiuxinum[jiuxinum.length-1]);
	}else{
		maxtc.style.display = "block"
	}	
});

closeBtn2.addEventListener('click',function(){
	maxtc.style.display = "none";
});

closeBtn3.addEventListener('click',function(){
	mintc.style.display = "none";
});
createBtn.onclick = function(){
	if(!window.localStorage){
		alert("浏览器不支持localstorage");
	}else{
		if(jiuxinum.length<4){
			mintc.style.display="block";
			tc.style.display = "none";
		}else{
			var storage = window.localStorage;
		index = index+1;
		storage.setItem('index',index);//储存在localstorage
		tc.style.display = "block";
		}
//		console.log(jiuxinum.length)
		
		if(index>10){
		index =10;
		storage.setItem('index',index);//储存在localstorage
		tc.style.display = "block";
		}
		
	}
	
}
